package com.gem.controller;

import com.alibaba.druid.util.StringUtils;
import com.gem.domain.Company;
import com.gem.domain.CompanyVisit;
import com.gem.domain.User;
import com.gem.service.CompanyService;
import com.gem.service.CompanyVisitService;
import com.gem.service.UserService;
import com.gem.util.ExcelUtil;
import com.gem.util.JSONResultUtil;
import com.gem.util.MessageUtil;
import com.gem.util.PageUtil;
import com.github.pagehelper.PageInfo;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Bravea❤ ·勇
 * Description: 企业拜访记录controller
 * create
 * Modified By:
 */
@Controller
@RequestMapping("/comVisit")
public class CompanyVisitController {

    @Autowired
    private JSONResultUtil result;
    
    @Autowired
    private UserService userService;
    
    @Autowired
    private CompanyService companyService;

    @Autowired
    private CompanyVisitService companyVisitService;

    @RequestMapping("/visitList")
    public String visitList(Model model,String coId,String pageNow,HttpSession session,
                              @RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,
                              @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        User user = (User) session.getAttribute("user");
        if (user == null) {
            MessageUtil.returnInfoPage("3", "/starter", "用户未登录", model);
            return "message";
        }
        PageInfo<CompanyVisit> pageBean = null;
        if(coId != null && !coId.equals("") && pageNow != null && !pageNow.equals("")){
            if(user.getDepartment() != null && user.getDepartment().equals("hrc") && user.getAuthority() == 1){
                pageBean = companyVisitService.selectCompanyVisitByCompanyId(currentPage, pageSize, coId);
            }else if (user.getDepartment() != null && user.getDepartment().equals("hrc") && user.getJob().equals("企培") && user.getAuthority() == 2){
                pageBean = companyVisitService.selectCompanyVisitEByCompanyId(currentPage, pageSize, coId);
            }else if (user.getDepartment() != null && user.getDepartment().equals("hrc") && user.getJob().equals("就业") && user.getAuthority() == 2){
                pageBean = companyVisitService.selectCompanyVisitJByCompanyId(currentPage, pageSize, coId);
            }else {
                pageBean = companyVisitService.selectMyCompanyVisitByCompanyId(currentPage, pageSize, coId, user.getPersonname());
            }
        }else {
            coId = "";
            pageNow = "";
            if(user.getDepartment() != null && user.getDepartment().equals("hrc") && user.getAuthority() == 1){
                pageBean = companyVisitService.selectCompanyVisitByPage(currentPage,pageSize);
            }else if (user.getDepartment() != null && user.getDepartment().equals("hrc") && user.getJob().equals("企培") && user.getAuthority() == 2){
                pageBean = companyVisitService.selectCompanyVisitEByPage(currentPage,pageSize);
            }else if (user.getDepartment() != null && user.getDepartment().equals("hrc") && user.getJob().equals("就业") && user.getAuthority() == 2){
                pageBean = companyVisitService.selectCompanyVisitJByPage(currentPage,pageSize);
            }else {
                pageBean = companyVisitService.selectMyCompanyVisitByPage(currentPage,pageSize,user.getPersonname());
            }
        }
        if (currentPage > pageBean.getPages()){
            currentPage = pageBean.getPages();
            return "redirect:/comVisit/visitList?coId="+coId+"&pageNow="+pageNow+"&currentPage="+currentPage+"&pageSize="+pageSize;
        }
        if(pageBean != null && pageBean.getList().size() > 0){
            List<Integer> pageValue = PageUtil.getPageValue(pageBean.getPages(),currentPage);
            model.addAttribute("pageValue",pageValue);
        }else {
            model.addAttribute("info","没有拜访记录，请先添加！");
        }
        model.addAttribute("pageBean", pageBean);
        model.addAttribute("pageNow",pageNow);
        model.addAttribute("coId",coId);
        return "company/visit";
    }

    @RequestMapping("/visitModifyUI")
    public String visitModifyUI(String comVisitId,Model model,String searchUrl,String coId,String pageNow,
                                        @RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,
                                        @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        if(comVisitId == null || comVisitId.trim().equals("")){
            if(searchUrl == null){
                MessageUtil.returnInfoPage("3","/comVisit/visitList?currentPage="+currentPage+"&pageSize="+pageSize,"传递参数为空",model);
            }else {
                MessageUtil.returnInfoPage("3",searchUrl+"&currentPage="+currentPage+"&pageSize="+pageSize,"传递参数为空",model);
            }
            return "message";
        }
        CompanyVisit visits = companyVisitService.selectCompanyVisitById(comVisitId);
        if (visits == null){
            if (searchUrl == null){
                MessageUtil.returnInfoPage("3","/comVisit/visitList?currentPage="+currentPage+"&pageSize="+pageSize,"没有该拜访记录",model);
            }else {
                MessageUtil.returnInfoPage("3",searchUrl+"&currentPage="+currentPage+"&pageSize="+pageSize,"没有该拜访记录",model);
            }
            return "message";
        }
        List<User> hrcs = userService.findHrc();
        List<Company> allCompany = companyService.findAllCompany();
        if(hrcs==null || hrcs.size() <= 0 || allCompany==null || allCompany.size() <= 0){
            if(searchUrl != null && !searchUrl.trim().equals("")){
                MessageUtil.returnInfoPage("3",searchUrl+"&currentPage=" + currentPage + "&pageSize=" + pageSize,"没有企业或HRC人员，请先添加",model);
            }else {
                MessageUtil.returnInfoPage("3","/comVisit/visitList?currentPage=" + currentPage + "&pageSize=" + pageSize + "&coId=" + coId + "&pageNow=" + pageNow,"没有企业或HRC人员，请先添加",model);
            }
            return "message";
        }
        if(coId == null){
            coId = "";
        }
        if(pageNow == null){
            pageNow = "";
        }
        model.addAttribute("coId",coId);
        model.addAttribute("pageNow",pageNow);
        model.addAttribute("hrcs",hrcs);
        model.addAttribute("allCompany",allCompany);
        model.addAttribute("searchUrl",searchUrl);
        model.addAttribute("currentPage",currentPage);
        model.addAttribute("pageSize",pageSize);
        model.addAttribute("visits",visits);
        return "company/visit_update";
    }

    @RequestMapping("/visitModify")
    public String visitModify(CompanyVisit com,Model model,String searchUrl,String coId,String pageNow,
                                      @RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,
                                      @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        boolean isModifySuccess = companyVisitService.modifyCompanyVisitById(com);
        if(isModifySuccess){
            if(searchUrl != null && !searchUrl.trim().equals("")){
                MessageUtil.returnInfoPage("3",searchUrl+"&currentPage="+currentPage+"&pageSize="+pageSize,"修改成功！",model);
            }else {
                MessageUtil.returnInfoPage("3", "/comVisit/visitList?currentPage=" + currentPage + "&pageSize=" + pageSize + "&coId=" + coId + "&pageNow=" + pageNow, "修改成功！", model);
            }
        }else {
            if(searchUrl != null && !searchUrl.trim().equals("")){
                MessageUtil.returnInfoPage("3",searchUrl+"&currentPage="+currentPage+"&pageSize="+pageSize,"修改失败，请检查！",model);
            }else {
                MessageUtil.returnInfoPage("3", "/comVisit/visitList?currentPage=" + currentPage + "&pageSize=" + pageSize + "&coId=" + coId + "&pageNow=" + pageNow, "修改失败，请检查！", model);
            }
        }
        return "message";
    }

    @RequestMapping("/visitAddUI")
    public String visitAddUI(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,String searchUrl,String coId,
                                     @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,Model model,String pageNow){
        List<User> hrcs = userService.findHrc();
        List<Company> allCompany = companyService.findAllCompany();
        if(hrcs == null || hrcs.size() <= 0 || allCompany == null || allCompany.size() <= 0){
            if(searchUrl!=null&&!searchUrl.trim().equals("")){
                MessageUtil.returnInfoPage("3",searchUrl+"&currentPage=" + currentPage + "&pageSize=" + pageSize,"没有企业或HRC人员，请先添加",model);
            }else {
                MessageUtil.returnInfoPage("3","/comVisit/visitList?currentPage=" + currentPage + "&pageSize=" + pageSize + "&coId=" + coId + "&pageNow=" + pageNow,"没有企业或HRC人员，请先添加",model);
            }
            return "message";
        }
        if(coId == null){
            coId = "";
        }
        if(pageNow == null){
            pageNow = "";
        }
        model.addAttribute("coId",coId);
        model.addAttribute("pageNow",pageNow);
        model.addAttribute("hrcs",hrcs);
        model.addAttribute("allCompany",allCompany);
        model.addAttribute("currentPage",currentPage);
        model.addAttribute("pageSize",pageSize);
        model.addAttribute("searchUrl",searchUrl);
        return "company/visit_insert";
    }

    @RequestMapping("/visitAdd")
    public String visitAdd(CompanyVisit com,Model model,String searchUrl,String coId,String pageNow,
                                   @RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,
                                   @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        boolean isAddSuccess = companyVisitService.addCompanyVisit(com);
        if(isAddSuccess){
            if(searchUrl != null && !searchUrl.trim().equals("")){
                MessageUtil.returnInfoPage("3",searchUrl+"&currentPage="+currentPage+"&pageSize="+pageSize,"添加成功！",model);
            }else {
                MessageUtil.returnInfoPage("3","/comVisit/visitList?currentPage=" + currentPage + "&pageSize=" + pageSize + "&coId=" + coId + "&pageNow=" + pageNow,"添加成功！",model);
            }
        }else {
            if(searchUrl != null && !searchUrl.trim().equals("")){
                MessageUtil.returnInfoPage("3",searchUrl+"&currentPage="+currentPage+"&pageSize="+pageSize,"添加失败，请检查！",model);
            }else {
                MessageUtil.returnInfoPage("3","/comVisit/visitList?currentPage=" + currentPage + "&pageSize=" + pageSize + "&coId=" + coId + "&pageNow=" + pageNow,"添加失败，请检查！",model);
            }
        }
        return "message";
    }

    @RequestMapping("/visitSearch")
    public String visitSearch(Model model,String comVisitDate,CompanyVisit com,HttpSession session,
                                      @RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,
                                      @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        User user = (User) session.getAttribute("user");
        if (user == null) {
            MessageUtil.returnInfoPage("3", "/starter", "用户未登录", model);
            return "message";
        }
        if(comVisitDate == null){
            comVisitDate = "";
        }
        if (com.getCoName() == null){
            com.setCoName("");
        }
        if (com.getPersonname() == null){
            com.setPersonname("");
        }
        PageInfo<CompanyVisit> pageBean = null;
        if(user.getDepartment() != null && user.getDepartment().equals("hrc") && user.getAuthority() == 1){
            pageBean = companyVisitService.searchCompanyVisitByPage(currentPage,pageSize,com.getCoName(),com.getPersonname(),com.getComVisitDate());
        }else if (user.getDepartment() != null && user.getDepartment().equals("hrc") && user.getJob().equals("企培") && user.getAuthority() == 2){
            pageBean = companyVisitService.searchCompanyVisitEByPage(currentPage,pageSize,com.getCoName(),com.getPersonname(),com.getComVisitDate());
        }else if (user.getDepartment() != null && user.getDepartment().equals("hrc") && user.getJob().equals("就业") && user.getAuthority() == 2){
            pageBean = companyVisitService.searchCompanyVisitJByPage(currentPage,pageSize,com.getCoName(),com.getPersonname(),com.getComVisitDate());
        }else {
            pageBean = companyVisitService.searchCompanyVisitByPage(currentPage,pageSize,com.getCoName(),com.getPersonname(),com.getComVisitDate());
        }
        if (currentPage > pageBean.getPages()){
            currentPage = pageBean.getPages();
            pageBean = companyVisitService.searchCompanyVisitByPage(currentPage,pageSize,com.getCoName(),com.getPersonname(),com.getComVisitDate());
        }
        if(pageBean != null && pageBean.getList().size() > 0 && pageBean.getPages() > 0 && pageBean.getTotal() > 0){
            List<Integer> pageValue = PageUtil.getPageValue(pageBean.getPages(),currentPage);
            model.addAttribute("pageValue",pageValue);
        }else {
            model.addAttribute("info","没有拜访记录，请先添加！");
        }
        model.addAttribute("pageBean",pageBean);
        model.addAttribute("coName",com.getCoName());
        model.addAttribute("personname",com.getPersonname());
        model.addAttribute("comVisitDate",comVisitDate);
        model.addAttribute("searchUrl","/comVisit/visitSearch?personname="+com.getPersonname()+"&coName="+com.getCoName()+"&comVisitDate="+comVisitDate);
        return "company/visit";
    }

    @RequestMapping(value = "/visitDelete",method = RequestMethod.POST)
    @ResponseBody
    public JSONResultUtil visitDelete(String[] checks){
        try {
            if (checks != null && checks.length>0) {
                if (companyVisitService.deleteCompanyVisitById(checks)) {
                    result.setId(0);
                    result.setData("删除成功！");
                } else {
                    result.setId(-1);
                    result.setData("删除失败！");
                    System.out.println("失败了？？？");
                }
            } else {
                result.setId(-1);
                result.setData("没有提交编号参数哦！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.setId(-1);
            result.setData("服务器异常，请联系管理员哦！");
        }
        return result;
    }

    /**
     * 以下是POI部分
     */
    //导出excel模板
    @RequestMapping("/exportTemplate")
    public void exportExcelTemplate(HttpServletResponse response, HttpSession session){
        try {
            //创建excel工作簿对象//一个表格文件！
            HSSFWorkbook workbook = new HSSFWorkbook();
            //创建sheet对象//一个表单！
            HSSFSheet sheet = workbook.createSheet("Sheet1");

            //创建水平垂直居中的cellStyle单元格样式对象
            HSSFCellStyle cellStyle = ExcelUtil.getTitleStyle(workbook);

            //创建水平垂直居中加粗的cellStyle单元格样式,给表头试用
            HSSFCellStyle cellStyle2 = ExcelUtil.getThStyle(workbook);

            //模板第一行例子展示
            HSSFCellStyle cellStyle3 = ExcelUtil.getExamplStyle(workbook);

            // 单元格类型日期格式化
            HSSFCellStyle cellStyleDate = ExcelUtil.getDateRedStyle(workbook);

            //创建行对象
            HSSFRow row = null;

            // 将第一行的三个单元格给合并,模板固定
            //注意 java的参数是从0开始 即表示excel中的一行或者第一列  //Row行 Col列
            sheet = getRows(sheet, cellStyle, cellStyle2);
            User user = (User) session.getAttribute("user");
            String[] trainHrcs = {user.getPersonname()};
            sheet = ExcelUtil.setHSSFValidation(sheet, trainHrcs, 3, 10000, 4, 4);
            //在第四行给一行数据模板,根据对应表的对应字段填写
            row = sheet.createRow(3);
            row.createCell(0).setCellValue("苏州高博应诺");
            //第二列 缴费日期
            //优化 降低冗余
            HSSFCell cell = null;//主要用于表格里时间的格式化
            cell = row.createCell(1);
            cell.setCellStyle(cellStyleDate);
            cell.setCellValue(new Date());
            //第三列 拜访人
            row.createCell(2).setCellValue("张三");
            //第四列 拜访事件
            row.createCell(3).setCellValue("学术交流");
            //第五列 拜访发起人
            row.createCell(4).setCellValue(user.getPersonname());
            //第六列 洽谈方式
            row.createCell(5).setCellValue("面谈");
            //第七列 洽谈内容
            row.createCell(6).setCellValue("友谊第一比赛第二");
            //第九列 备注
            row.createCell(7).setCellValue("备注可写可不写");

            for (int i = 0; i < 8; i++) {
                if (i != 1) {
                    row.getCell(i).setCellStyle(cellStyle3);//时间有时间的格式
                }
            }

            OutputStream outputStream = response.getOutputStream();
            response.reset();
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition", "attachment;filename=companyVisit.xls");

            workbook.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //导出excel
    @RequestMapping("/export")
    public void exportExcel(HttpServletResponse response) {
        try {
            //创建excel工作簿对象
            HSSFWorkbook workbook = new HSSFWorkbook();
            //创建sheet对象
            HSSFSheet sheet = workbook.createSheet("Sheet1");

            //创建水平垂直居中的cellStyle单元格样式对象
            HSSFCellStyle cellStyle = ExcelUtil.getTitleStyle(workbook);

            //创建水平垂直居中加粗的cellStyle单元格样式,给表头试用
            HSSFCellStyle cellStyle2 = ExcelUtil.getThStyle(workbook);

            //居中
            HSSFCellStyle cellStyle3 = ExcelUtil.getCenterStyle(workbook);

            // 单元格类型日期格式化
            HSSFCellStyle cellStyleDate = ExcelUtil.getDateStyle(workbook);

            //创建行对象
            HSSFRow row = null;
            sheet = getRows(sheet, cellStyle, cellStyle2);
            List<User> hrc = userService.findHrc();
            String[] trainHrcs = new String[hrc.size()];
            int index = 0;
            for (User user : hrc) {
                trainHrcs[index] = user.getPersonname();
                index++;
            }
            sheet = ExcelUtil.setHSSFValidation(sheet, trainHrcs, 3, 10000, 4, 4);
            //调用service方法查询所有数据集合
            List<CompanyVisit> companyVisits = companyVisitService.selectAllCompanyVisit();

            CompanyVisit visit = null;

            for (int i = 0; i < companyVisits.size(); i++) {
                row = sheet.createRow(i + 3);
                visit = companyVisits.get(i);
                //第一列,企业名称
                row.createCell(0).setCellValue(visit.getCoName());
                //优化 降低冗余
                HSSFCell cell = null;//主要用于表格里时间的格式化
                //第二列 拜访日期
                cell = row.createCell(1);
                cell.setCellStyle(cellStyleDate);
                cell.setCellValue(visit.getComVisitDate());
                //第三列 拜访人
                row.createCell(2).setCellValue(visit.getComVisitVisitor());
                //第四列 拜访事件
                row.createCell(3).setCellValue(visit.getComVisitPurpose());
                //第五列 拜访发起人
                row.createCell(4).setCellValue(visit.getPersonname());
                //第六列 洽谈方式
                row.createCell(5).setCellValue(visit.getComVisitType());
                //第七列 洽谈内容
                row.createCell(6).setCellValue(visit.getComVisitDetails());
                //第八列 备注
                row.createCell(7).setCellValue(visit.getComVisitRemarks());

                //设置垂直水平居中
                for (int j = 0; j < 8; j++) {
                    if(j!=1){
                        row.getCell(j).setCellStyle(cellStyle3);
                    }
                }
            }

            OutputStream outputStream = response.getOutputStream();
            response.reset();
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition", "attachment;filename=template.xls");

            workbook.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //导出模板和导出数据抽出的共同方法
    private HSSFSheet getRows(HSSFSheet sheet, HSSFCellStyle cellStyle, HSSFCellStyle cellStyle2) {
        HSSFRow row;// 将第一行的三个单元格给合并,模板固定
        //注意 java的参数是从0开始 即表示excel中的一行或者第一列
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 7));
        row = sheet.createRow(0);
        HSSFCell beginCell0 = row.createCell(0);
        beginCell0.setCellValue("企业拜访记录表");
        //cellStyle为水平居中字体加粗单元格样式
        beginCell0.setCellStyle(cellStyle);

        //第二行的单元格进行合并,语句提示
        sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 7));
        row = sheet.createRow(1);
        HSSFCell beginCell1 = row.createCell(0);
        beginCell1.setCellValue("请按照模板字段和单元格格式提交数据,日期类型请使用给定格式刷刷一下");
        //cellStyle为水平居中字体加粗单元格样式
        beginCell1.setCellStyle(cellStyle);

        HSSFRow headRow = sheet.createRow(2);
        headRow.createCell(0).setCellValue("*企业名称");
        headRow.createCell(1).setCellValue("*拜访日期");
        headRow.createCell(2).setCellValue("拜访人");
        headRow.createCell(3).setCellValue("拜访事件");
        headRow.createCell(4).setCellValue("*拜访发起人");
        headRow.createCell(5).setCellValue("*洽谈方式");
        headRow.createCell(6).setCellValue("洽谈内容");
        headRow.createCell(7).setCellValue("备注");
        headRow.setHeightInPoints(25); //设置行的高度
        for (int i = 0; i < 8; i++) {
            headRow.getCell(i).setCellStyle(cellStyle2);
        }

        //下拉列表的参数
        String[] visitType = {"面谈", "电话", "其他"};
        List<Company> companys = companyService.findAllCompany();
        String[] companyNames = new String[companys.size()];
        int index = 0;
        for (Company company : companys) {
            companyNames[index] = company.getCoName();
            index++;
        }
        //设置当前工作表的什么地方需要下拉,需要自己对着表格设置位置,没有就不需要写
        sheet = ExcelUtil.setHSSFValidation(sheet, visitType, 3, 10000, 5, 5);
        sheet = ExcelUtil.setHSSFValidation(sheet, companyNames, 3, 10000, 0, 0);

        //设置所有列列宽
        for (int i = 0; i < 8; i++) {
            sheet.setColumnWidth(i, 20 * 256);
        } // 设置列的宽度
        return sheet;
    }

    //导入excel
    @RequestMapping("/import")
    public String importExcel(@RequestParam("file") MultipartFile file, Model model, HttpSession session) {
        //固定格式  参数file 为 文件上传的input的name
        try {
            InputStream inputStream = null;
            inputStream = file.getInputStream();
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
            HSSFWorkbook workbook = new HSSFWorkbook(file.getInputStream());

            HSSFSheet sheet = workbook.getSheetAt(0);

            int lastRowNum = sheet.getLastRowNum();
            CompanyVisit visit = null;
            HSSFRow row = null;

            System.out.println("lastRowNum======"+lastRowNum);
            //从第四行开始读取数据
            List<CompanyVisit> list = new ArrayList<>();
            for (int i = 3; i <= lastRowNum; i++) {
                visit = new CompanyVisit();
                row = sheet.getRow(i);
                if(StringUtils.isEmpty(row.getCell(0).getStringCellValue()) && StringUtils.isEmpty(row.getCell(4).getStringCellValue())){
                    break;//如果企业名称和拜访发起人都为空则判断以下是空行无数据，停止写入
                }
                //第一列
                Company company = companyService.findByName(row.getCell(0).getStringCellValue());
                visit.setComVisitCompanyId(company.getCoId());
                //第二列 连起来写 直接给ds对象赋值
                visit.setComVisitDate(row.getCell(1).getDateCellValue());
                //第三列
                visit.setComVisitVisitor(row.getCell(2).getStringCellValue());
                //第四列
                visit.setComVisitPurpose(row.getCell(3).getStringCellValue());
                //第五列
                User user = (User)session.getAttribute("user");//自己导入自己的表格，直接拿登录的user
                visit.setComVisitInitiatorId(user.getUid());
                //第六列
                visit.setComVisitType(row.getCell(5).getStringCellValue());
                //第七列
                visit.setComVisitDetails(row.getCell(6).getStringCellValue());
                //第八列
                visit.setComVisitRemarks(row.getCell(7).getStringCellValue());
                //添加一个对象,循环,直到结束
                list.add(visit);
            }
            if (companyVisitService.addCompanyVisitList(list)){
                MessageUtil.returnInfoPage("2","/comVisit/visitList","导入成功",model);
                return "message";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        MessageUtil.returnInfoPage("3", "/comVisit/visitList", "导入失败！请检查", model);
        return "message";
    }

}
